package com.example.demo.util;

import com.example.demo.pojo.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class RequestContext {

    public static HttpServletRequest getRequest(){
        //通过`RequestContextHolder`获取当前request请求对象
        return ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
    }


    public static User getUser(){
        return (User) getRequest().getSession().getAttribute("user");
    }

}
